<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.keywords" placeholder="订单编号、消费者账号、消费者名称" clearable style="width: 300px"></el-input>
      </el-form-item>
      <el-form-item label="">
		<el-date-picker
          v-model="dataForm.startTime"
          type="datetime"
          value-format = "yyyy-MM-dd HH:mm:ss"
          placeholder="起始时间">
		</el-date-picker>
	  </el-form-item>
	  <el-form-item label="">
		<el-date-picker
          v-model="dataForm.endTime"
          type="datetime"
          value-format = "yyyy-MM-dd HH:mm:ss"
          placeholder="结束时间">
		</el-date-picker>
	  </el-form-item>
      <el-form-item label="类型">
	    <el-select v-model="dataForm.type" placeholder="类型">
		  <el-option label="全部" value=""></el-option>
		  <el-option label="福利订单返佣" value="1"></el-option>
		  <el-option label="分享赚" value="2"></el-option>
		  <el-option label="推广金额" value="3"></el-option>
      <el-option label="联盟店线上订单佣金" value="4"></el-option>
		  <el-option label="区域线下买单佣金" value="5"></el-option>
		  <el-option label="新用户首单奖励" value="6"></el-option>
      <el-option label="推广充值返现" value="7"></el-option>
		  <el-option label="推广订单交易返现" value="8"></el-option>
		</el-select>
	  </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button @click="
          dataForm.keywords = ''
          dataForm.startTime = ''
          dataForm.endTime = ''
          dataForm.type = ''
          getDataList()">重置</el-button>
        <el-button v-if="isAuth('returnCommission:orderReturnExcel')" icon="el-icon-download" type="primary" @click="excel()">订单返佣</el-button>
        <el-button v-if="isAuth('returnCommission:promotionCommissionExcel')" icon="el-icon-download" type="primary" @click="excel1()">推广佣金</el-button>
        <!-- <el-button v-if="isAuth('goods:shoppingbusinessgoods:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button> -->
        <!-- <el-button v-if="isAuth('goods:shoppingbusinessgoods:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button> -->
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <!-- <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column> -->
      <el-table-column
        prop="createTime"
        header-align="center"
        align="center"
        label="创建时间">
      </el-table-column>
      <el-table-column
        prop="orderNo"
        header-align="center"
        align="center"
        label="订单编号">
      </el-table-column>
      <el-table-column
        prop="payUserName"
        header-align="center"
        align="center"
        label="消费者账号">
      </el-table-column>
      <el-table-column
        prop="payTrueName"
        header-align="center"
        align="center"
        label="消费者名称">
      </el-table-column>
      <el-table-column
        prop="payUserType"
        header-align="center"
        align="center"
        label="消费者类型">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.payUserType === 1">区域运营商</el-tag>
          <el-tag v-else-if ="scope.row.payUserType === 2">普通联盟店</el-tag>
          <el-tag v-else-if ="scope.row.payUserType === 3">消费者</el-tag>
          <el-tag v-else-if ="scope.row.payUserType == 4">VIP会员</el-tag>
          <el-tag v-else-if ="scope.row.payUserType == 5">中级版联盟店</el-tag>
          <el-tag v-else-if ="scope.row.payUserType == 6">高级版联盟店</el-tag>
          <el-tag v-else-if ="scope.row.payUserType == 7">城市合伙人</el-tag>
          <el-tag v-else-if ="scope.row.payUserType == 8">城市合伙人联盟店</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="commissionMoney"
        header-align="center"
        align="center"
        label="佣金获得金额">
        <template slot-scope="scope">
          <span v-if="scope.row.commissionMoney != null">￥ {{scope.row.commissionMoney}}</span>
          <span v-if="scope.row.commissionMoney == null">￥ 0</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="commissionPercent"
        header-align="center"
        align="center"
        label="消费者用户的佣金百分比">
        <template slot-scope="scope">
          <span>{{scope.row.commissionPercent * 100 .toFixed(2) + ' %'}}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="goodsProfits"
        header-align="center"
        align="center"
        label="商品总利润">
      </el-table-column>
      <el-table-column
        prop="goodsPrice"
        header-align="center"
        align="center"
        label="商品零售价格">
        <template slot-scope="scope">
          <span v-if="scope.row.goodsPrice != null">￥ {{scope.row.goodsPrice}}</span>
          <span v-if="scope.row.goodsPrice == null">￥ 0</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="orderType"
        header-align="center"
        align="center"
        label="订单类型">
        <template slot-scope="scope">
          <span v-if="scope.row.orderType === 1">兑换商城</span>
          <span v-if="scope.row.orderType === 2 || scope.row.orderType === 0">福利商城</span>
          <span v-if="scope.row.orderType === 3">联盟店线上买单</span>
          <span v-if="scope.row.orderType === 4">联盟店线下买单</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="storeName"
        header-align="center"
        align="center"
        label="商家名">
      </el-table-column>
      <el-table-column
        prop="commissionType"
        header-align="center"
        align="center"
        label="类型">
        <template slot-scope="scope">
          <p v-if="scope.row.commissionType == 1">订单返佣</p>
          <p v-if="scope.row.commissionType == 2">分享赚</p>
          <p v-if="scope.row.commissionType == 3">推广金额</p>
          <p v-if="scope.row.commissionType == 4">联盟店线上订单佣金</p>
          <p v-if="scope.row.commissionType == 5">区域线下买单佣金</p>
          <p v-if="scope.row.commissionType == 6">新用户首单奖励</p>
          <p v-if="scope.row.commissionType == 7">推广充值返现</p>
          <p v-else-if="scope.row.commissionType == 8">推广订单交易返现</p>
        </template>
      </el-table-column>
      <el-table-column
        prop="userName"
        header-align="center"
        align="center"
        label="收佣者账号">
      </el-table-column>
      <el-table-column
        prop="trueName"
        header-align="center"
        align="center"
        label="收佣者名称">
      </el-table-column>
      <el-table-column
        prop="realName"
        header-align="center"
        align="center"
        label="收佣者负责人">
      </el-table-column>
      <el-table-column
        prop="getUserType"
        header-align="center"
        align="center"
        label="收佣者类型">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.getUserType == 1">区域运营商</el-tag>
          <el-tag v-else-if ="scope.row.getUserType == 2">普通联盟店</el-tag>
          <el-tag v-else-if ="scope.row.getUserType == 3">消费者</el-tag>
          <el-tag v-else-if ="scope.row.getUserType == 4">VIP会员</el-tag>
          <el-tag v-else-if ="scope.row.getUserType == 5">中级版联盟店</el-tag>
          <el-tag v-else-if ="scope.row.getUserType == 6">高级版联盟店</el-tag>
          <el-tag v-else-if ="scope.row.getUserType == 7">城市合伙人</el-tag>
          <el-tag v-else-if ="scope.row.getUserType == 8">城市合伙人联盟店</el-tag>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </div>
</template>

<script>
  export default {
    data () {
      return {
        dataForm: {
          keywords: '',
          startTime: '',
          endTime: '',
          type: ''
        },
        commissionPercent: '',
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/returnCommission/queryOrderReturnList'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'keywords': this.dataForm.keywords,
            'startTime': this.dataForm.startTime,
            'endTime': this.dataForm.endTime,
            'type': this.dataForm.type
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.data.list
            this.totalPage = data.data.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      excel () {
        window.location.href = this.$http.adornUrl(`/returnCommission/orderReturnExcel?token=${this.$cookie.get('token')}&type=${this.dataForm.type}&startTime=${this.dataForm.startTime}&endTime=${this.dataForm.endTime}&keywords=${this.dataForm.keywords}`)
      },
      excel1 () {
        window.location.href = this.$http.adornUrl(`/returnCommission/promotionCommissionExcel?token=${this.$cookie.get('token')}&type=${this.dataForm.type}&startTime=${this.dataForm.startTime}&endTime=${this.dataForm.endTime}&keywords=${this.dataForm.keywords}`)
      }
    }
  }
</script>
